package com.ssy.lingxi.purchase.serviceimpl.tender;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.ssy.lingxi.common.constant.Constants;
import com.ssy.lingxi.common.constant.member.MemberTypeEnum;
import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.component.rabbitMQ.service.IRabbitMQUtils;
import com.ssy.lingxi.component.redis.service.IRedisStringUtils;
import com.ssy.lingxi.component.redis.utils.SerialNumberUtils;
import com.ssy.lingxi.message.api.constant.MessageTemplateCode;
import com.ssy.lingxi.message.api.feign.SystemMessageControllerFeign;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import com.ssy.lingxi.purchase.api.dto.request.tender.*;
import com.ssy.lingxi.purchase.api.enums.tender.*;
import com.ssy.lingxi.purchase.entity.tender.*;
import com.ssy.lingxi.purchase.repository.tender.*;
import com.ssy.lingxi.purchase.service.tender.ISubmitTenderService;
import com.ssy.lingxi.report.api.constant.ReportConstants;
import com.ssy.lingxi.report.api.enums.OperateDataSourceEnum;
import com.ssy.lingxi.report.api.enums.PurchaseInviteTenderOperateTypeEnum;
import com.ssy.lingxi.report.api.enums.PurchaseTenderOperateTypeEnum;
import com.ssy.lingxi.report.api.vo.request.OperateNoticeAddVO;
import com.ssy.lingxi.report.api.vo.request.OperateNoticeVO;
import com.ssy.lingxi.search.api.model.request.SimpleIdListRequest;
import com.ssy.lingxi.workflow.api.feign.ProcessFeign;
import com.ssy.lingxi.workflow.api.model.contant.ProcessEnum;
import com.ssy.lingxi.workflow.api.model.vo.request.ExternalProcessQueryVO;
import com.ssy.lingxi.workflow.api.model.vo.request.InternalProcessQueryVO;
import com.ssy.lingxi.workflow.api.model.vo.request.TaskExecuteVO;
import com.ssy.lingxi.workflow.api.model.vo.request.TaskStartVO;
import com.ssy.lingxi.workflow.api.model.vo.response.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 投标实现类
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/3/1
 */
@Service
public class SubmitTenderServiceImpl implements ISubmitTenderService {

    @Resource
    private InviteTenderRepository inviteTenderRepository;

    @Resource
    private InviteTenderMemberRepository inviteTenderMemberRepository;

    @Resource
    private TenderOutCheckRecordRepository tenderOutCheckRecordRepository;

    @Resource
    private SubmitTenderInCheckRecordRepository submitTenderInCheckRecordRepository;

    @Resource
    private SubmitTenderOutCheckRecordRepository submitTenderOutCheckRecordRepository;

    @Resource
    private InviteTenderMaterielRepository inviteTenderMaterielRepository;

    @Resource
    private ProcessFeign processFeign;

    @Resource
    private SystemMessageControllerFeign systemMessageControllerFeign;

    @Resource
    private IRedisStringUtils redisStringUtils;

    @Resource
    private IRabbitMQUtils rabbitMQUtils;

    /**
     * 查询投标列表
     * @param sysUser
     * @param inviteTenderQueryRequest
     * @return
     */
    @Override
    public Page<InviteTenderMember> getInviteTenderList(UserLoginCacheDTO sysUser, InviteTenderQueryRequest inviteTenderQueryRequest) {
        Pageable page = PageRequest.of(inviteTenderQueryRequest.getCurrent() - 1, inviteTenderQueryRequest.getPageSize());
        return inviteTenderMemberRepository.findAll(getSpecification(sysUser, inviteTenderQueryRequest), page);
    }

    /**
     * 构建查询条件
     * @param sysUser
     * @param inviteTenderQueryRequest
     * @return
     */
    private Specification<InviteTenderMember> getSpecification(UserLoginCacheDTO sysUser, InviteTenderQueryRequest inviteTenderQueryRequest) {
        return new Specification<InviteTenderMember>() {
            @Override
            public Predicate toPredicate(Root<InviteTenderMember> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
                Predicate finalConditions = criteriaBuilder.conjunction();
                Long memberId = sysUser.getMemberId();
                Long memberRoleId = sysUser.getMemberRoleId();
                String inviteTenderMemberName = inviteTenderQueryRequest.getInviteTenderMemberName();
                String inviteTenderCode = inviteTenderQueryRequest.getInviteTenderCode();
                String projectName = inviteTenderQueryRequest.getProjectName();
                List<Integer> submitTenderInStatusList = inviteTenderQueryRequest.getSubmitTenderInStatusList();
                List<Integer> submitTenderOutStatusList = inviteTenderQueryRequest.getSubmitTenderOutStatusList();
                Long startTime = inviteTenderQueryRequest.getStartTime();
                Long endTime = inviteTenderQueryRequest.getEndTime();

                //会员id
                if(memberId != null && memberId > 0){
                    Predicate predicate = criteriaBuilder.equal(root.get("memberId"), memberId);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //会员角色id
                if(memberRoleId != null && memberRoleId > 0){
                    Predicate predicate = criteriaBuilder.equal(root.get("memberRoleId"), memberRoleId);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //招标会员
                if(!StringUtils.isEmpty(inviteTenderMemberName)){
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("memberName").as(String.class), "%" + inviteTenderMemberName + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //招标编号
                if(!StringUtils.isEmpty(inviteTenderCode)){
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("code").as(String.class), "%" + inviteTenderCode + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //招标项目名
                if(!StringUtils.isEmpty(projectName)){
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("projectName").as(String.class), "%" + projectName + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //内部状态
                if(submitTenderInStatusList != null && submitTenderInStatusList.size() > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.in(root.get("submitTenderInStatus")).value(submitTenderInStatusList));
                }

                //外部状态
                if(submitTenderOutStatusList != null && submitTenderOutStatusList.size() > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.in(root.get("submitTenderOutStatus")).value(submitTenderOutStatusList));
                }

                //发布时间
                if(startTime != null && startTime > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("inviteTender").get("createTime"), startTime));
                }
                if(endTime != null && endTime > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("inviteTender").get("createTime"), endTime));
                }

                //只关联发送的投标人员
                finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.equal(root.get("isSend"), true));
                finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.notEqual(root.get("submitTenderOutStatus"), 0));

                //排序
                Order idOrder = criteriaBuilder.desc(root.get("id"));

                return  query.distinct(true).orderBy(idOrder).where(finalConditions).getRestriction();
            }
        };
    }

    /**
     * 查询投标列表
     * @param sysUser
     * @param submitTenderQueryRequest
     * @return
     */
    @Override
    public Page<InviteTenderMember> getSubmitTenderList(UserLoginCacheDTO sysUser, SubmitTenderQueryRequest submitTenderQueryRequest) {
        Pageable page = PageRequest.of(submitTenderQueryRequest.getCurrent() - 1, submitTenderQueryRequest.getPageSize());
        return inviteTenderMemberRepository.findAll(getSubmitTenderSpecification(sysUser, submitTenderQueryRequest), page);
    }

    /**
     * 构建查询条件
     * @param sysUser
     * @param submitTenderQueryRequest
     * @return
     */
    private Specification<InviteTenderMember> getSubmitTenderSpecification(UserLoginCacheDTO sysUser, SubmitTenderQueryRequest submitTenderQueryRequest) {
        return new Specification<InviteTenderMember>() {
            @Override
            public Predicate toPredicate(Root<InviteTenderMember> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
                Predicate finalConditions = criteriaBuilder.conjunction();
                Long memberId = sysUser.getMemberId();
                Long memberRoleId = sysUser.getMemberRoleId();
                String inviteTenderCode = submitTenderQueryRequest.getInviteTenderCode();
                String submitTenderCode = submitTenderQueryRequest.getSubmitTenderCode();
                String projectName = submitTenderQueryRequest.getProjectName();
                List<Integer> submitTenderInStatusList = submitTenderQueryRequest.getSubmitTenderInStatusList();
                List<Integer> submitTenderOutStatusList = submitTenderQueryRequest.getSubmitTenderOutStatusList();
                Long openTenderStartTime = submitTenderQueryRequest.getOpenTenderStartTime();
                Long openTenderEndTime = submitTenderQueryRequest.getOpenTenderEndTime();
                Long submitTenderStartTime = submitTenderQueryRequest.getSubmitTenderStartTime();
                Long submitTenderEndTime = submitTenderQueryRequest.getSubmitTenderEndTime();
                String inviteTenderMemberName = submitTenderQueryRequest.getInviteTenderMemberName();
                Boolean isQualificationCheck = submitTenderQueryRequest.getIsQualificationCheck();
                Long startTime = submitTenderQueryRequest.getStartTime();
                Long endTime = submitTenderQueryRequest.getEndTime();

                Boolean isSelectSubmit = submitTenderQueryRequest.getIsSelectSubmit();

                //会员id
                if(memberId != null && memberId > 0){
                    Predicate predicate = criteriaBuilder.equal(root.get("memberId"), memberId);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //会员角色id
                if(memberRoleId != null && memberRoleId > 0){
                    Predicate predicate = criteriaBuilder.equal(root.get("memberRoleId"), memberRoleId);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //招标会员
                if(!StringUtils.isEmpty(inviteTenderMemberName)){
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("memberName").as(String.class), "%" + inviteTenderMemberName + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //招标编号
                if(!StringUtils.isEmpty(inviteTenderCode)){
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("code").as(String.class), "%" + inviteTenderCode + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //招标项目名
                if(!StringUtils.isEmpty(projectName)){
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("projectName").as(String.class), "%" + projectName + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //投标编号
                if(!StringUtils.isEmpty(submitTenderCode)){
                    Predicate predicate = criteriaBuilder.like(root.get("code").as(String.class), "%" + submitTenderCode + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //是否需要资格预审
                if(isQualificationCheck != null){
                    Predicate predicate = criteriaBuilder.equal(root.get("inviteTender").get("isQualificationCheck"), isQualificationCheck);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //内部状态
                if(submitTenderInStatusList != null && submitTenderInStatusList.size() > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.in(root.get("submitTenderInStatus")).value(submitTenderInStatusList));
                }

                //外部状态
                if(submitTenderOutStatusList != null && submitTenderOutStatusList.size() > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.in(root.get("submitTenderOutStatus")).value(submitTenderOutStatusList));
                }

                //开标时间
                if(openTenderStartTime != null && openTenderStartTime > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("inviteTender").get("openTenderTime"), openTenderStartTime));
                }
                if(openTenderEndTime != null && openTenderEndTime > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("inviteTender").get("openTenderTime"), openTenderEndTime));
                }

                //投标时间
                if(submitTenderStartTime != null && submitTenderStartTime > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("submitTenderTime"), submitTenderStartTime));
                }
                if(submitTenderEndTime != null && submitTenderEndTime > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("submitTenderTime"), submitTenderEndTime));
                }

                //发布时间
                if(startTime != null && startTime > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("inviteTender").get("createTime"), startTime));
                }
                if(endTime != null && endTime > 0){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("inviteTender").get("createTime"), endTime));
                }

                //只关联发送的投标人员
                finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.equal(root.get("isSend"), true));
                finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.notEqual(root.get("submitTenderOutStatus"), 0));

                //是否只查看投标后的数据
                if(isSelectSubmit != null && isSelectSubmit){
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("submitTenderOutStatus"), SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode()));
                }

                //排序
                Order idOrder = criteriaBuilder.desc(root.get("id"));

                return  query.distinct(true).orderBy(idOrder).where(finalConditions).getRestriction();
            }
        };
    }

    /**
     * 查询招标
     * @param inviteTenderId
     * @return InviteTender
     */
    @Override
    public InviteTenderMember getInviteTenderMember(UserLoginCacheDTO sysUser, Long inviteTenderId){
        List<InviteTenderMember> inviteTenderMemberList = inviteTenderMemberRepository.findByMemberIdAndMemberRoleIdAndInviteTenderId(sysUser.getMemberId(), sysUser.getMemberRoleId(), inviteTenderId);
        if(inviteTenderMemberList != null && inviteTenderMemberList.size() > 0){
            if(inviteTenderMemberList.size() == 1){
                return inviteTenderMemberList.get(0);
            }
        }
        return null;
    }

    /**
     * 查询投标信息
     * @param sysUser
     * @param submitTenderId
     * @return
     */
    @Override
    public InviteTenderMember getSubmitTenderMember(UserLoginCacheDTO sysUser, Long submitTenderId) {
        return inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
    }

    /**
     * 投标报名
     * @param sysUser
     * @param submitTenderRegisterRequest
     * @return
     */
    @Transactional
    @Override
    public String submitTenderRegister(UserLoginCacheDTO sysUser, SubmitTenderRegisterRequest submitTenderRegisterRequest) {
        Long inviteTenderId = submitTenderRegisterRequest.getInviteTenderId();
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if(inviteTender != null) {
            //判断投标开始时间
            long registerStartTime = inviteTender.getRegisterStartTime();
            long registerEndTime = inviteTender.getRegisterEndTime();
            long now = System.currentTimeMillis();
            if (now >= registerStartTime && now <= registerEndTime) {
                Long memberId = sysUser.getMemberId();
                Long memberRoleId = sysUser.getMemberRoleId();
                List<InviteTenderMember> memberList = inviteTender.getMemberList();
                Integer inviteTenderType = inviteTender.getInviteTenderType();
                InviteTenderMember inviteTenderMember = null;

                //判断是否已经报名了
                if(memberList != null && memberList.size() > 0){
                    for (InviteTenderMember existInviteTenderMember : memberList) {
                        //投标会员
                        Long submitTenderMemberId = existInviteTenderMember.getMemberId();
                        Long submitTenderMemberRoleId = existInviteTenderMember.getMemberRoleId();
                        Integer submitTenderOutStatus = existInviteTenderMember.getSubmitTenderOutStatus();
                        SubmitTender submitTender = existInviteTenderMember.getSubmitTender();
                        if (memberId.longValue() == submitTenderMemberId.longValue() && memberRoleId.longValue() == submitTenderMemberRoleId.longValue()) {
                            if (SubmitTenderOutStatusEnum.Register_Check_Not_Pass.getCode().intValue() != submitTenderOutStatus && submitTender != null) {
                                throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_EXIST);
                            } else {
                                //报名审核不通过
                                inviteTenderMember = BeanUtil.copyProperties(existInviteTenderMember, InviteTenderMember.class);
                            }
                        }
                    }
                }
                if (InviteTenderTypeEnum.Open.getCode().intValue() == inviteTenderType.intValue()) {
                    if(inviteTenderMember == null){
                        //会员信息
                        inviteTenderMember = new InviteTenderMember();
                        inviteTenderMember.setInviteTender(inviteTender);
                        inviteTenderMember.setIsSend(true);
                        inviteTenderMember.setMemberId(memberId);
                        inviteTenderMember.setMemberName(sysUser.getCompany());
                        inviteTenderMember.setMemberRoleId(memberRoleId);
                        inviteTenderMember.setMemberRoleName(sysUser.getMemberRoleName());
                        inviteTenderMember.setIsSubMember(false);
                        inviteTenderMember.setMemberTypeName(MemberTypeEnum.getMessage(sysUser.getMemberType()));
                    }
                }else {
                    if(inviteTenderMember == null){
                        throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
                    }
                }
                SubmitTenderRegister submitTenderRegister = BeanUtil.copyProperties(submitTenderRegisterRequest, SubmitTenderRegister.class);
                List<SubmitTenderRegisterFile> registerFile = submitTenderRegister.getRegisterFile();
                if(registerFile != null){
                    registerFile.forEach(submitTenderRegisterFile -> {
                        submitTenderRegisterFile.setSubmitTenderRegister(submitTenderRegister);
                    });
                }
                inviteTenderMember.setSubmitTenderRegister(submitTenderRegister);
                //外部状态
                Integer newSubmitTenderOutStatus = SubmitTenderOutStatusEnum.Not_Check_Register_Check.getCode();
                //内部状态
                Integer submitTenderInStatus = SubmitTenderInStatusEnum.Submitted_Invite_Tender_Register.getCode();

                inviteTenderMember.setSubmitTenderOutStatus(newSubmitTenderOutStatus);
                inviteTenderMember.setSubmitTenderInStatus(submitTenderInStatus);
                inviteTenderMemberRepository.saveAndFlush(inviteTenderMember);

                List<InviteTenderMember> inviteTenderMemberList = new ArrayList<>();
                inviteTenderMemberList.add(inviteTenderMember);
                inviteTender.setMemberList(inviteTenderMemberList);
                inviteTenderRepository.saveAndFlush(inviteTender);

                //记录投标内部状态
                SubmitTenderInCheckRecord submitTenderInCheckRecord = new SubmitTenderInCheckRecord();
                submitTenderInCheckRecord.setUserId(sysUser.getUserId());
                submitTenderInCheckRecord.setUserName(sysUser.getUserName());
                submitTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
                submitTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
                submitTenderInCheckRecord.setMemberId(memberId);
                submitTenderInCheckRecord.setMemberName(sysUser.getCompany());
                submitTenderInCheckRecord.setMemberRoleId(memberRoleId);
                submitTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                submitTenderInCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Submit_Tender_Register.getCode()));
                submitTenderInCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
                submitTenderInCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                submitTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
                submitTenderInCheckRecordRepository.saveAndFlush(submitTenderInCheckRecord);

                //记录投标外部状态
                SubmitTenderOutCheckRecord submitTenderOutCheckRecord = new SubmitTenderOutCheckRecord();
                submitTenderOutCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                submitTenderOutCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                submitTenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                submitTenderOutCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                submitTenderOutCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Submit_Tender_Register.getCode()));
                submitTenderOutCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
                submitTenderOutCheckRecordRepository.saveAndFlush(submitTenderOutCheckRecord);

                //首页数据统计
                try {
                    List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                    if (InviteTenderTypeEnum.Open.getCode().intValue() != inviteTenderType.intValue()) {
                        //待招标报名-1
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                        operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_SIGNUP_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                    }
                    //待审核报名+1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_SIGNUP_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                    OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                    rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTender.getMemberId());
                    systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_audit_register);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTender.getCode());
                    params.add(inviteTender.getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                }catch (Exception e){
                    e.printStackTrace();
                }

                return ResponseCode.SUCCESS.getMessage();
            } else {
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_REGISTER_TIME);
            }
        }
        throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
    }

    /**
     * 提交资格预审
     * @param submitQualificationsRequest
     * @return
     */
    @Transactional
    @Override
    public String submitQualifications(UserLoginCacheDTO sysUser, SubmitQualificationsRequest submitQualificationsRequest) {
        Long submitTenderId = submitQualificationsRequest.getSubmitTenderId();
        InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
        if(inviteTenderMember == null){
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
        }
        InviteTender inviteTender = inviteTenderMember.getInviteTender();
        Boolean isQualificationCheck = inviteTender.getIsQualificationCheck();
        if(isQualificationCheck){
            //判断是否超过提交资格预审时间
            Long preCheckStartTime = inviteTender.getPreCheckStartTime();
            Long preCheckEndTime = inviteTender.getPreCheckEndTime();
            long now = System.currentTimeMillis();
            if(now >= preCheckStartTime && now <= preCheckEndTime){
                List<InviteTenderFileRequest> qualificationsFileList = submitQualificationsRequest.getQualificationsFile();
                List<SubmitTenderQualificationsFile> submitTenderQualificationsFileList = qualificationsFileList.stream().map(inviteTenderFileRequest -> {
                    SubmitTenderQualificationsFile submitTenderQualificationsFile = BeanUtil.copyProperties(inviteTenderFileRequest, SubmitTenderQualificationsFile.class);
                    submitTenderQualificationsFile.setInviteTenderMember(inviteTenderMember);
                    return submitTenderQualificationsFile;
                }).collect(Collectors.toList());
                inviteTenderMember.setQualificationsFile(submitTenderQualificationsFileList);

                //外部状态
                Integer newSubmitTenderOutStatus = SubmitTenderOutStatusEnum.Not_Qualifications_Check.getCode();
                //内部状态
                Integer submitTenderInStatus = SubmitTenderInStatusEnum.Submitted_Qualifications_Check.getCode();

                inviteTenderMember.setSubmitTenderOutStatus(newSubmitTenderOutStatus);
                inviteTenderMember.setSubmitTenderInStatus(submitTenderInStatus);
                inviteTenderMember.setSubmitQualificationsCheckTime(System.currentTimeMillis());
                inviteTenderMemberRepository.saveAndFlush(inviteTenderMember);

                //记录内部状态
                SubmitTenderInCheckRecord submitTenderInCheckRecord = new SubmitTenderInCheckRecord();
                submitTenderInCheckRecord.setUserId(sysUser.getUserId());
                submitTenderInCheckRecord.setUserName(sysUser.getUserName());
                submitTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
                submitTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
                submitTenderInCheckRecord.setMemberId(sysUser.getMemberId());
                submitTenderInCheckRecord.setMemberName(sysUser.getCompany());
                submitTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                submitTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                submitTenderInCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Submit_Qualifications.getCode()));
                submitTenderInCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
                submitTenderInCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                submitTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
                submitTenderInCheckRecordRepository.saveAndFlush(submitTenderInCheckRecord);

                //记录投标外部状态
                SubmitTenderOutCheckRecord submitTenderOutCheckRecord = new SubmitTenderOutCheckRecord();
                submitTenderOutCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                submitTenderOutCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                submitTenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                submitTenderOutCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                submitTenderOutCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Submit_Qualifications.getCode()));
                submitTenderOutCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
                submitTenderOutCheckRecordRepository.saveAndFlush(submitTenderOutCheckRecord);

                //首页数据统计
                try {
                    //待提交资格预审-1
                    List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);
                    //待资格预审+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_QUALIFICATION_VALIFY_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                    OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                    rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTender.getMemberId());
                    systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_qualification_audit);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTender.getCode());
                    params.add(inviteTender.getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                }catch (Exception e){
                    e.printStackTrace();
                }
                return ResponseCode.SUCCESS.getMessage();
            }else{
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_QUALIFICATION_CHECK_TIME);
            }
        }else{
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_QUALIFICATION_CHECK);
        }
    }

    /**
     * 新增/修改投标
     * @param submitTenderRequest
     * @return
     */
    @Transactional
    @Override
    public String saveSubmitTender(UserLoginCacheDTO sysUser, SubmitTenderRequest submitTenderRequest) {
        Long submitTenderId = submitTenderRequest.getSubmitTenderId();
        InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
        if(inviteTenderMember == null){
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
        }
        Long id = submitTenderRequest.getId();
        if(id != null && id > 0){
            SubmitTender submitTender = inviteTenderMember.getSubmitTender();
            if(submitTender == null || submitTender.getId().intValue() != id.intValue()){
                throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
            }
        }

        //判断投标开始时间
        Long inviteTenderStartTime = inviteTenderMember.getInviteTender().getInviteTenderStartTime();
        Long inviteTenderEndTime = inviteTenderMember.getInviteTender().getInviteTenderEndTime();
        long now = System.currentTimeMillis();
        if(now >= inviteTenderStartTime && now <= inviteTenderEndTime){
            //投标信息
            SubmitTender submitTender = BeanUtil.copyProperties(submitTenderRequest, SubmitTender.class);
            List<SubmitTenderFile> submitTenderFileList = submitTender.getFile();
            if(submitTenderFileList != null && submitTenderFileList.size() > 0){
                submitTenderFileList.forEach(submitTenderFile -> {
                    submitTenderFile.setSubmitTender(submitTender);
                });
            }
            submitTender.setCreateTime(System.currentTimeMillis());
            //投标物流
            List<SubmitTenderMateriel> submitTenderMaterielList = new ArrayList<>();
            List<SubmitTenderMaterielRequest> submitTenderMaterielRequestList = submitTenderRequest.getSubmitTenderMateriel();
            submitTenderMaterielRequestList.forEach(submitTenderMaterielRequest -> {
                SimpleIdRequest simpleIdRequest = submitTenderMaterielRequest.getInviteTenderMateriel();
                if(simpleIdRequest != null){
                    InviteTenderMateriel inviteTenderMateriel = inviteTenderMaterielRepository.findById(simpleIdRequest.getId()).orElse(null);
                    if(inviteTenderMateriel == null){
                        throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_MATERIEL_NOT_EXIST);
                    }
                    SubmitTenderMateriel submitTenderMateriel = BeanUtil.copyProperties(submitTenderMaterielRequest, SubmitTenderMateriel.class);
                    submitTenderMateriel.setInviteTenderMateriel(inviteTenderMateriel);
                    submitTenderMateriel.setSubmitTender(submitTender);

                    List<SubmitTenderMaterielFile> file = submitTenderMateriel.getFile();
                    if(file != null && file.size() > 0){
                        file.forEach(submitTenderMaterielFile -> {
                            submitTenderMaterielFile.setSubmitTenderMateriel(submitTenderMateriel);
                        });
                    }

                    submitTenderMaterielList.add(submitTenderMateriel);
                    submitTender.setSubmitTenderMateriel(submitTenderMaterielList);
                }else{
                    throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_MATERIEL_NOT_EXIST);
                }
            });
            inviteTenderMember.setSubmitTender(submitTender);
            //内部状态
            Integer newSubmitTenderInStatus = SubmitTenderInStatusEnum.Not_Submitted_Check_Submit_Tender.getCode();
            inviteTenderMember.setSubmitTenderInStatus(newSubmitTenderInStatus);

            try{
                //启动投标流程
                TaskStartVO taskStartVO = new TaskStartVO();
                taskStartVO.setProcessKey(ProcessEnum.PURCHASE_SUBMIT_TENDER.getProcessKey());
                taskStartVO.setMemberId(inviteTenderMember.getMemberId());
                taskStartVO.setRoleId(inviteTenderMember.getMemberRoleId());
                taskStartVO.setDataId(inviteTenderMember.getId());
                Wrapper<SimpleTaskCompleteVO> SimpleTaskCompleteVOWrapper = processFeign.startSimpleProcessThenCompleteFirstTask(taskStartVO);
                if(ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()){
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer status = data.getStatus();
                    inviteTenderMember.setTaskId(taskId);
                    inviteTenderMember.setSubmitTenderInStatus(status);
                }
            }catch (Exception e){
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }

            //生成编码
            String submitTenderCode = SerialNumberUtils.getNumber(redisStringUtils, Constants.REDIS_KEY_PURCHASE_SUBMIT_TENDER, Constants.PURCHASE_INDEX, 6);
            inviteTenderMember.setCode(submitTenderCode);

            inviteTenderMemberRepository.saveAndFlush(inviteTenderMember);

            //记录内部状态
            SubmitTenderInCheckRecord submitTenderInCheckRecord = new SubmitTenderInCheckRecord();
            submitTenderInCheckRecord.setUserId(sysUser.getUserId());
            submitTenderInCheckRecord.setUserName(sysUser.getUserName());
            submitTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            submitTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            submitTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            submitTenderInCheckRecord.setMemberName(sysUser.getCompany());
            submitTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            submitTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            submitTenderInCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Add_Submit_Tender.getCode()));
            submitTenderInCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(SubmitTenderInStatusEnum.Not_Submitted_Check_Submit_Tender.getCode()));
            submitTenderInCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
            submitTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            submitTenderInCheckRecordRepository.saveAndFlush(submitTenderInCheckRecord);
        }else{
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_TIME);
        }
        return ResponseCode.SUCCESS.getMessage();
    }

    /**
     * 提交审核投标
     * @param sysUser
     * @param simpleIdListRequest
     * @return
     */
    @Transactional
    @Override
    public String submitCheckSubmitTender(UserLoginCacheDTO sysUser, SimpleIdListRequest simpleIdListRequest) {
        List<Long> idList = simpleIdListRequest.getIdList();
        List<InviteTenderMember> inviteTenderMemberList = new ArrayList<>();
        List<SubmitTenderInCheckRecord> submitTenderInCheckRecordList = new ArrayList<>();

        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
        List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
        idList.forEach(submitTenderId -> {
            //验证数据库中是否存在该数据
            InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
            if(inviteTenderMember != null){
                //判断投标开始时间
                Long inviteTenderStartTime = inviteTenderMember.getInviteTender().getInviteTenderStartTime();
                Long inviteTenderEndTime = inviteTenderMember.getInviteTender().getInviteTenderEndTime();
                long now = System.currentTimeMillis();
                if(now >= inviteTenderStartTime && now <= inviteTenderEndTime){
                    //持久化数据
                    Integer submitTenderInStatus = SubmitTenderInStatusEnum.Submitted_Check_Submit_Tender.getCode();
                    inviteTenderMember.setSubmitTenderInStatus(submitTenderInStatus);

                    try {
                        TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                        //执行工作流
                        taskExecuteVO.setTaskId(inviteTenderMember.getTaskId());
                        taskExecuteVO.setMemberId(inviteTenderMember.getMemberId());
                        taskExecuteVO.setRoleId(inviteTenderMember.getMemberRoleId());
                        taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_SUBMIT_TENDER.getProcessKey());
                        Wrapper<SimpleTaskCompleteVO> SimpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                        if(ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()){
                            SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                            String taskId = data.getTaskId();
                            Integer status = data.getStatus();
                            inviteTenderMember.setTaskId(taskId);
                            inviteTenderMember.setSubmitTenderInStatus(status);

                            submitTenderInStatus = status;
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                        throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                    }
                    inviteTenderMemberList.add(inviteTenderMember);

                    //记录内部状态
                    SubmitTenderInCheckRecord submitTenderInCheckRecord = new SubmitTenderInCheckRecord();
                    submitTenderInCheckRecord.setUserId(sysUser.getUserId());
                    submitTenderInCheckRecord.setUserName(sysUser.getUserName());
                    submitTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
                    submitTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
                    submitTenderInCheckRecord.setMemberId(sysUser.getMemberId());
                    submitTenderInCheckRecord.setMemberName(sysUser.getCompany());
                    submitTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                    submitTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                    submitTenderInCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Submit_Check_Tender.getCode()));
                    submitTenderInCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
                    submitTenderInCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                    submitTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
                    submitTenderInCheckRecordList.add(submitTenderInCheckRecord);

                    //待提交审核投标-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);
                    //待审核投标一级+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_audit_step_1);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTenderMember.getInviteTender().getCode());
                    params.add(inviteTenderMember.getInviteTender().getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                }else{
                    throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_TIME);
                }
            }else{
                throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
            }
        });
        //批量保存
        inviteTenderMemberRepository.saveAll(inviteTenderMemberList);
        submitTenderInCheckRecordRepository.saveAll(submitTenderInCheckRecordList);

        try {
            //首页数据统计
            OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
            OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
            rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
            //发送消息
            systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseCode.SUCCESS.getMessage();
    }

    /**
     * 审核投标
     * @param sysUser
     * @param checkRequest
     * @return
     */
    @Transactional
    @Override
    public String checkSubmitTender(UserLoginCacheDTO sysUser, CheckRequest checkRequest) {
        Long submitTenderId = checkRequest.getId();
        Boolean checkStatus = checkRequest.getCheckStatus();
        String checkRemark = checkRequest.getCheckRemark();
        //验证数据库中是否存在该数据
        InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
        if(inviteTenderMember != null){
            Integer currentSubmitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus();
            //持久化数据
            TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
            Integer submitTenderInStatus;
            List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
            List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
            if(checkStatus){
                //判断投标开始时间
                Long inviteTenderStartTime = inviteTenderMember.getInviteTender().getInviteTenderStartTime();
                Long inviteTenderEndTime = inviteTenderMember.getInviteTender().getInviteTenderEndTime();
                long now = System.currentTimeMillis();
                if(now < inviteTenderStartTime || now > inviteTenderEndTime){
                    throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_TIME);
                }
                submitTenderInStatus = SubmitTenderInStatusEnum.Not_Submitted_Submit_Tender.getCode();

                //通过
                taskExecuteVO.setAgree(ProcessAgreeEnum.Pass.getCode());

                if(SubmitTenderInStatusEnum.Submitted_Check_Submit_Tender.getCode().equals(currentSubmitTenderInStatus)){
                    //待审核投标二级-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //待提交投标+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_audit_step_2);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTenderMember.getInviteTender().getCode());
                    params.add(inviteTenderMember.getInviteTender().getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                }else{
                    //待审核投标一级-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //待审核投标二级+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_submit);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTenderMember.getInviteTender().getCode());
                    params.add(inviteTenderMember.getInviteTender().getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                }
            }else{
                submitTenderInStatus = SubmitTenderInStatusEnum.Check_Submit_Tender_Not_Pass.getCode();
                //不通过
                taskExecuteVO.setAgree(ProcessAgreeEnum.NotPass.getCode());

                if(SubmitTenderInStatusEnum.Submitted_Check_Submit_Tender.getCode().equals(currentSubmitTenderInStatus)){
                    //待审核投标二级-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //待审核投标一级+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_wait_audit);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTenderMember.getInviteTender().getCode());
                    params.add(inviteTenderMember.getInviteTender().getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                }else{
                    //待审核投标一级-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //待提交审核投标+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_audit_step_1);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTenderMember.getInviteTender().getCode());
                    params.add(inviteTenderMember.getInviteTender().getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                }

            }
            inviteTenderMember.setSubmitTenderInStatus(submitTenderInStatus);

            try {
                //执行工作流
                taskExecuteVO.setTaskId(inviteTenderMember.getTaskId());
                taskExecuteVO.setMemberId(inviteTenderMember.getMemberId());
                taskExecuteVO.setRoleId(inviteTenderMember.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_SUBMIT_TENDER.getProcessKey());
                Wrapper<SimpleTaskCompleteVO> SimpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if(ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()){
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer status = data.getStatus();
                    inviteTenderMember.setTaskId(taskId);
                    inviteTenderMember.setSubmitTenderInStatus(status);

                    submitTenderInStatus = status;
                }
            }catch (Exception e){
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }

            inviteTenderMemberRepository.saveAndFlush(inviteTenderMember);

            //记录内部状态
            SubmitTenderInCheckRecord submitTenderInCheckRecord = new SubmitTenderInCheckRecord();
            submitTenderInCheckRecord.setUserId(sysUser.getUserId());
            submitTenderInCheckRecord.setUserName(sysUser.getUserName());
            submitTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            submitTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            submitTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            submitTenderInCheckRecord.setMemberName(sysUser.getCompany());
            submitTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            submitTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            submitTenderInCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Check_Submit_Tender.getCode()));
            submitTenderInCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
            submitTenderInCheckRecord.setCheckRemark(checkRemark);
            submitTenderInCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
            submitTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            submitTenderInCheckRecordRepository.saveAndFlush(submitTenderInCheckRecord);

            try {
                //首页数据统计
                OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
                //发送消息
                systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
            }catch (Exception e){
                e.printStackTrace();
            }

            return ResponseCode.SUCCESS.getMessage();
        }else{
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
        }
    }

    /**
     * 批量审核投标通过
     * @param sysUser
     * @param simpleIdListRequest
     * @return
     */
    @Transactional
    @Override
    public String checkSubmitTenderBatch(UserLoginCacheDTO sysUser, SimpleIdListRequest simpleIdListRequest) {
        List<Long> idList = simpleIdListRequest.getIdList();
        List<InviteTenderMember> inviteTenderMemberList = new ArrayList<>();
        List<SubmitTenderInCheckRecord> submitTenderInCheckRecordList = new ArrayList<>();
        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
        List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
        idList.forEach(submitTenderId -> {
            //验证数据库中是否存在该数据
            InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
            if(inviteTenderMember != null){
                Integer currentSubmitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus();
                //判断投标开始时间
                Long inviteTenderStartTime = inviteTenderMember.getInviteTender().getInviteTenderStartTime();
                Long inviteTenderEndTime = inviteTenderMember.getInviteTender().getInviteTenderEndTime();
                long now = System.currentTimeMillis();
                if(now < inviteTenderStartTime || now > inviteTenderEndTime){
                    throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_TIME);
                }
                //持久化数据
                Integer submitTenderInStatus = SubmitTenderInStatusEnum.Not_Submitted_Submit_Tender.getCode();
                inviteTenderMember.setSubmitTenderInStatus(submitTenderInStatus);

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setAgree(ProcessAgreeEnum.Pass.getCode());
                    taskExecuteVO.setTaskId(inviteTenderMember.getTaskId());
                    taskExecuteVO.setMemberId(inviteTenderMember.getMemberId());
                    taskExecuteVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_SUBMIT_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if(ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()){
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer status = data.getStatus();
                        inviteTenderMember.setTaskId(taskId);
                        inviteTenderMember.setSubmitTenderInStatus(status);

                        submitTenderInStatus = status;
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }

                inviteTenderMemberList.add(inviteTenderMember);

                //记录内部状态
                SubmitTenderInCheckRecord submitTenderInCheckRecord = new SubmitTenderInCheckRecord();
                submitTenderInCheckRecord.setUserId(sysUser.getUserId());
                submitTenderInCheckRecord.setUserName(sysUser.getUserName());
                submitTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
                submitTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
                submitTenderInCheckRecord.setMemberId(sysUser.getMemberId());
                submitTenderInCheckRecord.setMemberName(sysUser.getCompany());
                submitTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                submitTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                submitTenderInCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Check_Submit_Tender.getCode()));
                submitTenderInCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
                submitTenderInCheckRecord.setCheckRemark(TenderStatusEnum.BATCH_CHECK_PASS.getMessage());
                submitTenderInCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                submitTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
                submitTenderInCheckRecordList.add(submitTenderInCheckRecord);

                if(SubmitTenderInStatusEnum.Submitted_Check_Submit_Tender.getCode().intValue() == currentSubmitTenderInStatus.intValue()){
                    //待审核投标二级-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //待提交投标+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_audit_step_2);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTenderMember.getInviteTender().getCode());
                    params.add(inviteTenderMember.getInviteTender().getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                }else{
                    //待审核投标一级-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //待审核投标二级+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_submit);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTenderMember.getInviteTender().getCode());
                    params.add(inviteTenderMember.getInviteTender().getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                }
            }else{
                throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
            }
        });
        inviteTenderMemberRepository.saveAll(inviteTenderMemberList);
        submitTenderInCheckRecordRepository.saveAll(submitTenderInCheckRecordList);

        try {
            //首页数据统计
            OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
            OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
            rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
            //发送消息
            systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseCode.SUCCESS.getMessage();
    }

    /**
     * 提交投标
     * @param sysUser
     * @param simpleIdListRequest
     * @return
     */
    @Transactional
    @Override
    public String submitSubmitTenderBatch(UserLoginCacheDTO sysUser, SimpleIdListRequest simpleIdListRequest) {
        List<Long> idList = simpleIdListRequest.getIdList();

        List<InviteTenderMember> inviteTenderMemberList = new ArrayList<>();
        List<SubmitTenderInCheckRecord> submitTenderInCheckRecordList = new ArrayList<>();
        List<SubmitTenderOutCheckRecord> submitTenderOutCheckRecordList = new ArrayList<>();
        List<InviterTenderOutCheckRecord> tenderOutCheckRecordList = new ArrayList<>();
        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
        List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
        idList.forEach(submitTenderId -> {
            //验证数据库中是否存在该数据
            InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
            if(inviteTenderMember != null){
                //判断投标开始时间
                Long inviteTenderStartTime = inviteTenderMember.getInviteTender().getInviteTenderStartTime();
                Long inviteTenderEndTime = inviteTenderMember.getInviteTender().getInviteTenderEndTime();
                long now = System.currentTimeMillis();
                if(now >= inviteTenderStartTime && now <= inviteTenderEndTime){
                    //持久化数据
                    Integer submitTenderInStatus = SubmitTenderInStatusEnum.Submitted_Submit_Tender.getCode();
                    Integer submitTenderOutStatus = SubmitTenderOutStatusEnum.Not_Open_Tender.getCode();
                    inviteTenderMember.setSubmitTenderInStatus(submitTenderInStatus);
                    inviteTenderMember.setSubmitTenderOutStatus(submitTenderOutStatus);
                    inviteTenderMember.setSubmitTenderTime(System.currentTimeMillis());

                    try {
                        //执行工作流
                        TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                        taskExecuteVO.setTaskId(inviteTenderMember.getTaskId());
                        taskExecuteVO.setMemberId(inviteTenderMember.getMemberId());
                        taskExecuteVO.setRoleId(inviteTenderMember.getMemberRoleId());
                        taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_SUBMIT_TENDER.getProcessKey());
                        Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                        if(ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()){
                            SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                            String taskId = data.getTaskId();
                            Integer status = data.getStatus();
                            inviteTenderMember.setTaskId(taskId);
                            inviteTenderMember.setSubmitTenderInStatus(status);

                            submitTenderInStatus = status;
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                        throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                    }
                    //已投标
                    inviteTenderMember.setIsSubmit(true);
                    inviteTenderMemberList.add(inviteTenderMember);

                    //记录内部状态
                    SubmitTenderInCheckRecord submitTenderInCheckRecord = new SubmitTenderInCheckRecord();
                    submitTenderInCheckRecord.setUserId(sysUser.getUserId());
                    submitTenderInCheckRecord.setUserName(sysUser.getUserName());
                    submitTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
                    submitTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
                    submitTenderInCheckRecord.setMemberId(sysUser.getMemberId());
                    submitTenderInCheckRecord.setMemberName(sysUser.getCompany());
                    submitTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                    submitTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                    submitTenderInCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Submit_Submit_Tender.getCode()));
                    submitTenderInCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
                    submitTenderInCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                    submitTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
                    submitTenderInCheckRecordList.add(submitTenderInCheckRecord);

                    //记录投标外部状态
                    SubmitTenderOutCheckRecord submitTenderOutCheckRecord = new SubmitTenderOutCheckRecord();
                    submitTenderOutCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                    submitTenderOutCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                    submitTenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                    submitTenderOutCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                    submitTenderOutCheckRecord.setOperationValue(SubmitTenderInOperationEnum.getMessage(SubmitTenderInOperationEnum.Submit_Submit_Tender.getCode()));
                    submitTenderOutCheckRecord.setStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
                    submitTenderOutCheckRecordList.add(submitTenderOutCheckRecord);


                    //待提交投标-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //待待专家评标+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getInviteTender().getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getInviteTender().getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_EXPERT_EVALUATION_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getInviteTender().getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getInviteTender().getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_expert_evaluate);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTenderMember.getInviteTender().getCode());
                    params.add(inviteTenderMember.getInviteTender().getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);

                    List<ExpertExtract> expertExtractList = inviteTenderMember.getInviteTender().getExpertExtractList();
                    if(expertExtractList != null && expertExtractList.size() > 0){
                        expertExtractList.forEach(expertExtract -> {
                            List<ExpertExtractRecord> expertExtractRecordList = expertExtract.getExpertExtractRecordList();
                            if(expertExtractRecordList != null && expertExtractRecordList.size() > 0){
                                expertExtractRecordList.forEach(expertExtractRecord -> {
                                    Expert expert = expertExtractRecord.getExpert();
                                    //发送消息
                                    SystemMessageRequest systemMessage = new SystemMessageRequest();
                                    systemMessage.setMemberId(expert.getMemberId());
                                    systemMessage.setRoleId(expert.getMemberRoleId());
                                    systemMessage.setUserId(expert.getExpertUserId());
                                    systemMessage.setMessageNotice(MessageTemplateCode.bidding_expert_evaluate);
                                    systemMessage.setParams(params);
                                    systemMessageRequestList.add(systemMessageRequest);
                                });
                            }
                        });
                    }
                }else{
                    throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_TIME);
                }
            }else{
                throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
            }
        });

        inviteTenderMemberRepository.saveAll(inviteTenderMemberList);
        submitTenderInCheckRecordRepository.saveAll(submitTenderInCheckRecordList);
        submitTenderOutCheckRecordRepository.saveAll(submitTenderOutCheckRecordList);
        tenderOutCheckRecordRepository.saveAll(tenderOutCheckRecordList);

        try {
            //首页数据统计
            OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
            OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
            rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
            //发送消息
            systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);

        }catch (Exception e){
            e.printStackTrace();
        }

        return ResponseCode.SUCCESS.getMessage();
    }

    /**
     * 查询流程步骤
     * @param sysUser
     * @param submitTenderId
     * @return
     */
    @Override
    public ComplexTaskDefVO getSubmitTenderProcess(UserLoginCacheDTO sysUser, Long submitTenderId) {
        try{
            ComplexTaskDefVO complexTaskDefVO = new ComplexTaskDefVO();
            List<ExternalTaskVO> externalTaskVOList = new ArrayList<>();
            List<InternalTaskVO> internalTaskVOList = new ArrayList<>();
            //验证数据库中是否存在该数据
            InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
            if(inviteTenderMember != null){
                String inviteTenderMemberTaskId = inviteTenderMember.getTaskId();
                if(inviteTenderMemberTaskId != null){
                    InternalProcessQueryVO internalProcessQueryVO = new InternalProcessQueryVO();
                    internalProcessQueryVO.setProcessKey(ProcessEnum.PURCHASE_SUBMIT_TENDER.getProcessKey());
                    internalProcessQueryVO.setTaskId(inviteTenderMember.getTaskId());
                    internalProcessQueryVO.setMemberId(sysUser.getMemberId());
                    Wrapper<SimpleProcessDefVO>  simpleProcessDefVOWrapper = processFeign.findSimpleInternalTaskDefinitions(internalProcessQueryVO);
                    if(ResponseCode.SUCCESS.getCode() == simpleProcessDefVOWrapper.getCode()){
                        SimpleProcessDefVO data = simpleProcessDefVOWrapper.getData();
                        Integer currentStep = data.getCurrentStep();
                        complexTaskDefVO.setCurrentInnerStep(currentStep);
                        List<SimpleTaskVO> tasks = data.getTasks();
                        tasks.forEach(externalTaskVO -> {
                            InternalTaskVO internalTaskVO = new InternalTaskVO();
                            internalTaskVO.setTaskName(externalTaskVO.getTaskName());
                            internalTaskVO.setTaskStep(externalTaskVO.getTaskStep());
                            internalTaskVO.setUserRoleName(externalTaskVO.getRoleName());
                            internalTaskVOList.add(internalTaskVO);
                        });
                    }
                }

                InviteTender inviteTender = inviteTenderMember.getInviteTender();
                if(inviteTender != null){
                    ExternalProcessQueryVO externalProcessQueryVO = new ExternalProcessQueryVO();
                    externalProcessQueryVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    externalProcessQueryVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    externalProcessQueryVO.setRoleId(inviteTender.getMemberRoleId());
                    externalProcessQueryVO.setSubRoleId(inviteTenderMember.getMemberRoleId());
                    Wrapper<SimpleProcessDefVO> inviteTenderSimpleProcessDefVOWrapper = processFeign.findSimpleExternalTaskDefinitions(externalProcessQueryVO);
                    if(ResponseCode.SUCCESS.getCode() == inviteTenderSimpleProcessDefVOWrapper.getCode()){
                        //招标流程
                        SimpleProcessDefVO data = inviteTenderSimpleProcessDefVOWrapper.getData();
                        List<SimpleTaskVO> tasks = data.getTasks();
                        String processName = data.getProcessName();
                        Integer currentStep = data.getCurrentStep();
                        complexTaskDefVO.setProcessName(processName);
                        complexTaskDefVO.setCurrentOuterStep(currentStep);
                        tasks.forEach(externalTask -> {
                            String taskName = externalTask.getTaskName();
                            Integer taskStep = externalTask.getTaskStep();
                            String roleName = externalTask.getRoleName();
                            ExternalTaskVO externalTaskVO = new ExternalTaskVO();
                            if(currentStep.intValue() == taskStep.intValue()){
                                externalTaskVO.setSubTasks(internalTaskVOList);
                            }
                            externalTaskVO.setTaskName(taskName);
                            externalTaskVO.setTaskStep(taskStep);
                            externalTaskVO.setMemberRoleName(roleName);
                            externalTaskVOList.add(externalTaskVO);
                        });
                        complexTaskDefVO.setExternalTasks(externalTaskVOList);
                        return complexTaskDefVO;
                    }
                    return null;
                }else{
                    throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
                }
            }else{
                throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
            }
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
        }
    }

}

